package com.augurit.gzcgwsp.jzfqwczz.common.web;

import java.util.List;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springside.modules.orm.Page;
import com.augurit.common.base.action.CrudActionSupport;
import com.augurit.gzcgwsp.jzfqwczz.common.service.IYwYnBusinfoNssyService;
import com.augurit.gzcgwsp.jzfqwczz.common.web.form.YwYnBusinfoNssyForm;
import com.augurit.gzcgwsp.ljzyz.service.IYwYnBusinfoService;
import com.augurit.gzcgwsp.ywcmn.entity.YwComQyxx;

@SuppressWarnings("serial")
@Results({
	@Result(name = CrudActionSupport.RELOAD, location = "yw-yn-businfo!nssyList.action", type = "redirect"),
	@Result(name = CrudActionSupport.SUCCESS, location = "/gzcgwsp/ywcmn/YwComClxx/YwComClxx.jsp"),
	@Result(name = "nssyEdit", location = "/gzcgwsp/ywcmn/YwComClxx/YwYnBusinfo-nssyEdit.jsp"),
	@Result(name = "nssyList", location = "/gzcgwsp/ywcmn/YwComClxx/YwYnBusinfo-nssyList.jsp")
})
public class YwYnBusinfoNssyAction extends CrudActionSupport<YwYnBusinfoNssyForm>{
	@Autowired
	private IYwYnBusinfoNssyService ywYnBusinfoNssyService;
	
	private YwYnBusinfoNssyForm form;
	private Long id;
	private Long[] checkedIds;
	private Page<YwYnBusinfoNssyForm> page = new Page<YwYnBusinfoNssyForm>(10);

    /**
     * 保存业务并关联流程实例
     */
    public String wfBusSave() {
    	
        return null;
    }
    
    
    
	@Override
	public String list() throws Exception {
		ywYnBusinfoNssyService.search(page, form);
		return SUCCESS;
	}
	
	@Override
    public String input() throws Exception {
		String busId= this.getRequest().getParameter("busId");
		form.setBusId(Long.parseLong(busId));
		List<YwYnBusinfoNssyForm> BusinfoNssyList = ywYnBusinfoNssyService.search(page, form).getResult();
		System.out.println("form.getGsmc() ==== ");
        return "nssyEdit";
    }


	/**
	 * �������������޸ĵ�Form����
	 */
	@Override
	public String save() throws Exception {
		if("合格".equals(form.getZhsyjl())){
			//如果通过审核
			form.setSts("2");//改状态审核完成
		}
		ywYnBusinfoNssyService.save(form,true);
		return RELOAD;
	}
	
    

	/**
	 * 全部审完
	 * @return
	 * @throws Exception
	 */
	public String doAllnssy() throws Exception{
		String ids=getParameter("ids");
		this.ywYnBusinfoNssyService.doAllnssy(ids);
		return null;
	}
	
	/**
	 * 编辑
	 * @return
	 * @throws Exception
	 */
	public String edit() throws Exception {
		String busId= this.getRequest().getParameter("busId");
		form = ywYnBusinfoNssyService.getEntity(busId,"1");
		form.setBusId(Long.parseLong(busId));
		if(form.getSts()==null){
			form.setSts("1");
		}
		getRequest().setAttribute("form", form);
		return "nssyEdit";
	}

	/**
	 * ɾ��һ����¼
	 */
	@Override
	public String delete() throws Exception {
		ywYnBusinfoNssyService.delete(id);
		return RELOAD;
	}
	
	/**
	 * ɾ�������¼
	 */
	@Override
	public String deleteMore() throws Exception{
		ywYnBusinfoNssyService.delete(checkedIds);
		return RELOAD;
	}
	
	   @Override
	    protected void prepareModel() throws Exception {
	        if(id != null){
	            form = ywYnBusinfoNssyService.get(id);
	        }
	        else
	            form = new YwYnBusinfoNssyForm();
	        
	        
	    }
	/**
	 * ׼��ҳ��ģ��
	 */

	public YwYnBusinfoNssyForm getModel() {
		return form;
	}
	
	// ����getter��setter����
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Long[] getCheckedIds() {
		return checkedIds;
	}

	public void setCheckedIds(Long[] checkedIds) {
		this.checkedIds = checkedIds;
	}
	
	public Page<YwYnBusinfoNssyForm> getPage() {
		return page;
	}


	public void setPage(Page<YwYnBusinfoNssyForm> page) {
		this.page = page;
	}

	public YwYnBusinfoNssyForm getForm() {
		return form;
	}

	public void setForm(YwYnBusinfoNssyForm form) {
		this.form = form;
	}
}
